<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <script>
            var myWorker = new SharedWorker("work.js");
            myWorker.port.onmessage = function(e) {
                console.log(e);
                if(e.data === 'ping'){
                    myWorker.port.postMessage('dong');
                }
            }
            myWorker.port.postMessage("aaaa");
            function sendMsg(){
                myWorker.port.postMessage(document.getElementById("msg").value);
            }
            onbeforeunload=function(){
                // myWorker.port.postMessage(0);
                myWorker.port.close();
            }
        </script>
    </body>
</html>